package cn.com.twoke.application.game.mario.core.ecs.component;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 数据组件
 */
public class DataComponent implements Component {
    /**
     * 数据集合
     */
    private Map<String, Object> dataMap = new ConcurrentHashMap<>();


    public void set(String key, Object value) {
        dataMap.put(key, value);
    }

    public <T> T get(String key) {
        return (T) dataMap.get(key);
    }


    public Object getOrPut(String key, Object defaultValue) {
        return dataMap.getOrDefault(key, defaultValue);
    }

    public String getString(String key) {
        return String.valueOf(dataMap.get(key));
    }

    public Integer getInt(String key) {
        return (Integer) dataMap.get(key);
    }

    public Long getLong(String key) {
        return (Long) dataMap.get(key);
    }


    public Double getDouble(String key) {
        return (Double) dataMap.get(key);
    }

}
